//
//  YZAutoInputCell.m
//  VET
//
//  Created by Lam BG on 2018/7/19.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZAutoInputCell.h"

#import "YZAutoRowModel.h"

@interface YZAutoInputCell ()

@property (weak, nonatomic) IBOutlet UILabel *inputTitle;

@property (weak, nonatomic) IBOutlet UILabel *tipsLabel;

@property (weak, nonatomic) IBOutlet UITextField *inputTF;

@end

@implementation YZAutoInputCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    @weakify(self);
    [self.inputTF.rac_textSignal subscribeNext:^(NSString *content) {
        
        @strongify(self);
        if ([@"dieoutNum" isEqualToString:self.rowModel.paramKey] ||
            [@"transferQty" isEqualToString:self.rowModel.paramKey]) {

            // 最大数字
            NSInteger inputNum = [content integerValue];
            if (inputNum > self.rowModel.maxValue) {

                inputNum = self.rowModel.maxValue;
                content = [@(inputNum) stringValue];
                self.inputTF.text = content;
            }
            self.rowModel.displayValue = self.rowModel.paramValue = content;
        } else {

            self.rowModel.displayValue = self.rowModel.paramValue = content;
        }
        
//        self.rowModel.displayValue = self.rowModel.paramValue = content;
    }];
}

- (void)setupCellView {
    [super setupCellView];
    
    if (self.rowModel.isNum) self.inputTF.keyboardType = UIKeyboardTypeDecimalPad;
    
    self.inputTitle.attributedText = [self.rowModel attributedTitle];
    self.inputTF.text = self.rowModel.displayValue;
    self.tipsLabel.text = self.rowModel.tips;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
